package com.zhanghe.study.spring4.annotation.config;

import com.zhanghe.study.spring4.annotation.bean.Person;
import com.zhanghe.study.spring4.annotation.bean.factory.PersonFactoryBean;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * config配置类 == 配置文件
 * @author zh
 * @date 2021/2/21 10:36
 */
@Configuration
//@ComponentScan(basePackages = {"com.zhanghe.study.spring4.annotation"},excludeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})
//})
@ComponentScan(basePackages = {"com.zhanghe.study.spring4.annotation"},
        useDefaultFilters = false,
        includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})

})
public class MainConfig {

    /**
     * bean的类型是返回类型，bean的id默认是方法名称
     * @return
     */
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    @Lazy
    public Person person(){
        return new Person("张三",18);
    }


    @Bean
    public PersonFactoryBean personFactoryBean(){
        return new PersonFactoryBean();
    }
}
